package chapter02

import chapter01.Student

object Test06_DataType {
  def main(args: Array[String]): Unit = {

    //正确
    var n1: Byte = 127
    var n2: Byte = -128


    //错误
    var n3: Byte = 120;
    //    var n4:Byte = -129


    // Scala 的整型，默认为 Int 型，声明 Long 型，须后加‘l’或‘L’
    var n5 = 10
    println(n5)
    var n6 = 9223372036854775807L
    println(n6)


    val b1: Byte = 10
    val b2: Byte = (10 + 20)
    println("b2 " + b2)


    // val b3 Byte = b1+20
    val b3: Byte = (b1 + 20).toByte
    println(b3)


    // 浮点类型 建议，在开发中需要高精度小数时，请选择 Double
    var n7 = 2.2345678912f
    var n8 = 2.2345678912
    println("n7=" + n7)
    println("n8=" + n8)


    //字符串
    var c1: Char = 'a'
    println(c1)

    val c2: Char = '9'
    println(c2)

    val c3: Char = '\t'
    println("s" + c3 + "33") //制表符

    val c4: Char = '\n'
    println("d" + c4 + "2") //换行付


    //空类型
    def m1(): Unit = {
      println("m1被低调用执行")
    }

    val a: Unit = m1()
    println("a: " + a)


    //空引用NULL
    //    var n: Int = null //error
    //    println(n)

    var student: Student = new Student("alice", 20)
    student = null
    println(student)


    // Nothing
    def m2(n: Int): Int = {
      if (n == 0)
        throw new NullPointerException
      else
        return n;

    }

    val b = m2(0)
    println(b)

  }

}
